class Api::V1::SpuTracksController < Api::V1::BaseController
  def index
    @spu_tracks = @current_user.spu_tracks.order("created_at DESC").page(params[:page]).per(params[:per])
  end

  def create
    if SpuTrack.find_or_create_by(user_id: @current_user.id, spu_id: params[:spu_id])
      render json: { result: true, message: '记录成功.' }, status: :ok
    else
      render json: { result: false, message: '记录失败.' }, status: :ok
    end
  end

  def destroy
    @spu_track = SpuTrack.find params[:id]
    if @spu_track.destroy
      render json: { result: true, message: '删除成功.' }, status: :ok
    else
      render json: { result: false, message: '删除失败.' }, status: :ok
    end
  end
  
end
